<template>
    <div class="company-info-container">
        <!-- 公司基本信息卡片 -->
        <el-card class="company-header-card">
            <div class="company-header">
                <!-- 左侧列：原有头像、公司基本信息 -->
                <el-col :span="16">
                    <div class="left-content">
                        <el-avatar :src="companyData.avatar" size="large" class="company-logo"></el-avatar>
                        <div class="company-base-info">
                            <div class="company-name-rating">
                                <h2 class="company-name">{{ companyData.name }}</h2>
                            </div>
                            <div class="company-meta">
                                <span><i class="el-icon-location-outline"></i>{{ companyData.location }}</span>
                                <span><i class="el-icon-s-cooperation" style="margin-right: 5px;"></i>{{
                                    companyData.companyIndustry }}</span>
                                <span><i class="el-icon-user" style="margin-right: 5px;"></i>{{ companyData.workTimeType
                                }}</span>
                            </div>
                        </div>
                    </div>
                </el-col>
                <!-- 右侧列：放目标的在招职位、BOSS 数量等 -->
                <el-col :span="8">
                    <div class="right-content">
                        <div class="stats">
                            <span class="stat-number">{{ companyData.companyPositionRespList.length }}</span>
                            <span class="stat-text">在招职位</span>
                            <span class="stat-number" style="margin-left: 20px;">{{
                                companyData.companyRecruiterRespList.length }}</span>
                            <span class="stat-text">位 BOSS</span>
                        </div>
                        <div class="create-time">
                            <span>创建时间：{{ formatDate(companyData.createDate) }}</span>
                        </div>
                    </div>
                </el-col>
            </div>
        </el-card>


        <el-card class="position-list">
            <div class="position-list-header">
                <h3>在招职位 ({{ companyData.companyPositionRespList.length }})</h3>
                <el-button type="text" class="view-all-btn" @click="viewAllPositions">查看全部岗位<i
                        class="el-icon-caret-right"></i></el-button>
            </div>

            <div class="position-list-content">
                <!-- 使用栅格系统控制布局，gutter设置为15px实现间隔 -->
                <el-row :gutter="8">
                    <!-- 每个卡片占8列（24/3=8），实现一行三个 -->
                    <el-col :span="8" v-for="position in positionList" :key="position.positionId">
                        <el-card class="position-item-card" @click.native="handleClick(position)">
                            <div class="job-content">
                                <div class="job-title-salary">
                                    <span class="job-title">{{ position.positionName }}</span>
                                    <span class="job-salary">{{ position.lowestSalaryMonth }} - {{
                                        position.highestSalaryMonth }}
                                    </span>
                                </div>
                                <div class="job-tags" style="text-align: left;">
                                    <span><i class="el-icon-time"></i> {{ position.positionType }}</span>
                                </div>
                                <div class="job-meta">
                                    <span> <i class="el-icon-office-building"></i>{{ position.companyName }}</span>
                                    <span class="job-location">{{ position.location }}</span>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                </el-row>
            </div>
        </el-card>


        <div class="content-wrapper">
            <!-- 栅格容器：gutter 控制列间距（15px） -->
            <el-row :gutter="15">
                <!-- 左侧：占 70%（24 栅格体系中，24*0.7≈17） -->
                <el-col :span="17">
                    <el-card class="company-intro-card">
                        <div class="company-intro-header">
                            <h3>公司简介</h3>
                        </div>
                        <div class="company-introduction">
                            <p>{{ companyData.companyIntroduction }}</p>
                        </div>
                    </el-card>
                </el-col>

                <!-- 右侧：占 30%（24-17=7） -->
                <el-col :span="7">
                    <el-card class="executive-card">
                        <div slot="header">
                            <h3>公司高管介绍</h3>
                        </div>
                        <div class="executive-content" v-for="executive in companyData.companyRecruiterRespList" :key="executive.userId" @click="executiveDetail(executive.userId)">
                            <el-avatar :src="executive.avatar" size="small"></el-avatar>
                            <span>{{ executive.name }}</span>
                        </div>
                    </el-card>
                </el-col>
            </el-row>
        </div>
    </div>
</template>

<script>
import { getCompanyDetail } from '@/util/seeker_api/company_detail.js'

export default {
    data() {
        return {
            companyData: null,
            positionList: null,
        }
    },
    methods: {
        async fetchCompanyDetail() {
            try {
                const id = this.$route.query.id
                if (id) {
                    const res = await getCompanyDetail(id)
                    this.companyData = res.data
                    this.positionList = res.data.companyPositionRespList.slice(0, 3)
                    console.log("获取公司详情成功", res)
                }
            } catch (error) {
                console.error('获取公司详情失败:', error)
                this.$message.error('获取公司详情失败')
            }
        },

        formatDate(dateStr) {
            if (!dateStr) return ''
            // 假设日期格式为 '2023-10-01T00:00:00' 或 '2023-10-01'
            const date = new Date(dateStr)
            return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`
        },

        viewAllPositions() {
            this.$router.push({
                name: 'job',
                query: { searchForm: {location:'',content:this.companyData.name } } // 参数会附加在 URL 中
            });
        },
        executiveDetail(userId) {
            this.$router.push({
                name: 'executive',
                query: { userId: userId }
            })
        },

        handleClick(position) {
            this.$router.push({
                name: 'job',
                query: {
                    job: position
                }
            })
        },

    },
    created() {
        this.fetchCompanyDetail()
    }
}
</script>

<style scoped>
.company-detail {
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.company-header-card {
    border-radius: 10px;
}

.company-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.left-content {
    display: flex;
    align-items: center;
}

.right-content {
    text-align: right;
}

.company-logo {
    width: 120px;
    height: 120px;
    object-fit: contain;
    margin-right: 20px;
}

.company-basic-info {
    flex: 1;
}

.company-name {
    margin: 0 0 10px 0;
    font-size: 24px;
    text-align: left;
}

.company-tags {
    margin-top: 10px;
}

.company-tags .el-tag {
    margin-right: 10px;
}

.company-description {
    margin-bottom: 30px;
}

.stat-number {
    font-size: 30px;
    margin: 5px;
}

.stats {
    margin-right: 20px;
}

.create-time {
    margin-top: 20px;
    color: #666;
}

.position-list {
    margin-top: 30px;
    border-radius: 10px;
    padding-bottom: auto;
}

.position-list-content {
    padding: 10px;
}

.position-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: hidden;
}

.view-all-btn {
    color: #41968d;
}

.view-all-btn:hover {
    color: #026e62;
}

/* 设置卡片圆角和阴影效果 */
.position-item-card {
    border-radius: 10px;
    /* 圆角10px */
    overflow: hidden;
    /* 确保内容不超出圆角 */
    transition: all 0.3s ease;
    /* 过渡动画 */
    height: 130px;
}

/* 卡片悬停效果（可选） */
.position-item-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

/* 确保卡片内容间距合适 */
.position-item {
    padding: 15px;
}

.job-title-salary {
    align-items: baseline;
    margin-bottom: 15px;
    display: flex;
    /* 开启 Flex 布局 */
    justify-content: space-between;
}

.job-title {
    font-size: 16px;
    margin-top: auto;
}

.job-salary {
    font-size: 18px;
    color: red;
}

.job-tags {
    margin-bottom: 15px;
}

.job-tags>span {
    width: 100%;
    margin-left: auto;
    font-size: 14px;
    background: #f3f5f7;
    padding: 5px;
    border-radius: 5px;
}

.job-meta {
    display: flex;
    /* 开启 Flex 布局 */
    justify-content: space-between;
}

.job-location {
    font-size: 14px;
    padding-left: 20%;
}

.content-wrapper{
    margin-top: 30px;
}

.company-intro-card{
    border-radius: 10px;
}

.executive-card{
    border-radius: 10px;
}

.company-intro-header{
    text-align: left;
    margin-bottom: 15px;
}

.company-introduction{
    text-align: left;
}

</style>